package top.hidoctor.auscultation.net.p;

import android.content.Context;

import com.tang.base.BaseResponse;
import com.tang.base.NetMapEncryptUtils;
import com.tang.base.PatchRequest;
import com.tang.net.SuccessConsumer;

import java.util.Map;

import io.reactivex.functions.Consumer;
import okhttp3.RequestBody;
import top.hidoctor.auscultation.net.PresenterWrapper;
import top.hidoctor.auscultation.net.c.ShaichaJieguoContract;
import top.hidoctor.auscultation.net.req.AssessReq;

public class ShaichaJieguoPresenter extends PresenterWrapper<ShaichaJieguoContract.View> implements ShaichaJieguoContract.Presenter {


    public ShaichaJieguoPresenter(Context context, ShaichaJieguoContract.View view) {
        super(context, view);
    }

    @Override
    public void assess(String id, AssessReq req) {
        mView.showLoading();
        Map<String, Object> map = new NetMapEncryptUtils(req).getMaps();
        RequestBody body = new PatchRequest(map).getRequestBody();
        add(mService.screenAssess(id, body)
                .compose(this.getTransformer())
                .subscribe(new SuccessConsumer<BaseResponse<Object>>(mView, mContext) {
                    @Override
                    public void onSuccess(BaseResponse<Object> response) {
                        mView.hideLoading();
                        mView.assessSuc();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        throwable.printStackTrace();
                    }
                }));
    }
}
